#include<iostream>
using namespace std;
using ll = long long;
const int N = 2e5 + 9;
int a[N];

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--)
	{
		ll sum = 0;
		int n; cin >> n;
		for (int i = 0; i < n; ++i)
			cin >> a[i];

		int m; cin >> m;
		for (int i = 1; i <= m; ++i)
		{
			int x; cin >> x;
			sum += x;
		}
		ll k = sum % n;
		cout << a[k] << '\n';
	}

	return 0;
}